<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>申请成为工人</title>
    <link rel="stylesheet" type="text/css" href="../../../css/aui/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../../css/html/issued/post_your_want_frm.css" />
    <style>
        .up_image_box {
            display: flex;
            justify-content: space-between;
        }

        .up_image {
            width: calc(33.33% - 0.4rem);
            height: 29vw;
            border: 1px solid #E1E1E1;
            margin-right: 0.6rem;
            margin-bottom: 1rem;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .up_image:last-child {
            margin-right: 0;
        }
    </style>
</head>

<body>
    <div id="app">
        <div style="background:#ebebeb;padding:0.5rem 0.75rem;">
            <div style="margin:1rem 0 0.5rem 0;">审核结果：</div>
            <div><textarea class="textarea" disabled v-model="info.auth_result" style="border-color:#a2a2a2;height:4rem;"></textarea></div>
        </div>
        <div class="aui-content aui-margin-b-15">
            <ul class="aui-list aui-form-list">
                <li class="aui-list-item">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">户籍</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.residence" placeholder="请填写身份证上的户籍所在地">
                        </div>
                    </div>
                </li>
                <li class="aui-list-item" style="border-bottom:0.5rem solid #eee;">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">详细住址</div>
                        <div class="aui-list-item-input">
                            <input type="text" v-model="info.address" placeholder="请填写现居住详细地址">
                        </div>
                    </div>
                </li>
            </ul>

            <div class="aui-content-padded">
                <div>
                    <div style="margin:1rem 0 0.5rem 0;">身份证照片<small style="font-size:0.5rem;color:#B7B7B7;">(证件正反面，单个图片大小不要超过2MB)</small></div>
                    <div class="up_image_box" style="justify-content:flex-start;">
                        <div class="up_image" @click="addImg('idcard1')">
                            <img v-if="info.idcard1" :src="info.idcard1" alt="">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                        <div class="up_image" @click="addImg('idcard2')">
                            <img v-if="info.idcard1" :src="info.idcard2" alt="">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                    </div>
                </div>
            </div>

            <ul class="aui-list aui-form-list">
                <li class="aui-list-item" style="border-top:0.5rem solid #eee;" @click="openWork()">
                    <div class="aui-list-item-inner">
                        <div class="aui-list-item-label">工种</div>
                        <div class="aui-margin-r-15">{{info.work_cate_name}}</div>
                    </div>
                </li>
            </ul>

            <div style="border-bottom:0.5rem solid #eee;">
                <div class="aui-content-padded">
                    <div style="margin:1rem 0 0.5rem 0;">证书照片<small style="font-size:0.5rem;color:#B7B7B7;">(最多上传3张图，单个图片大小不要超过2MB)</small></div>
                    <div class="up_image_box" style="justify-content:flex-start;">
                        <div class="up_image" @click="addImg('certificate1',1)">
                            <img v-if="certificate1" :src="certificate1" alt="">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                        <div class="up_image" @click="addImg('certificate2',1)">
                            <img v-if="certificate2" :src="certificate2" alt="">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                        <div class="up_image" @click="addImg('certificate3',1)">
                            <img v-if="certificate3" :src="certificate3" alt="">
                            <img v-else src="../../../image/icon/shangchuan1.png" alt="">
                        </div>
                    </div>
                </div>
            </div>
            <div>
                <div class="aui-content-padded">
                    <div style="margin:1rem 0 0.5rem 0;">工作履历</div>
                    <div><textarea class="textarea" v-model="info.work_record" placeholder="请输入个人工作经验"></textarea></div>
                </div>
            </div>
            <div class="btn" v-if="info.auth_status===2" @click="submit()">更新认证</div>
        </div>
    </div>
</body>
<script src="../../../script/api.js" charset="utf-8"></script>
<script src="../../../script/aui/aui-tab.js" charset="utf-8"></script>
<script src="../../../script/common/jquery-3.3.1.min.js" charset="utf-8"></script>
<script src="../../../script/common/check.js" charset="utf-8"></script>
<script src="../../../script/common/common.js" charset="utf-8"></script>
<script src="../../../script/common/config.js" charset="utf-8"></script>
<script src="../../../script/common/vue.min.js" charset="utf-8"></script>
<script>
    apiready = function() {
        api.parseTapmode();
        vm.init();
    }

    var vm = new Vue({
        el: "#app",
        data: {
            userInfo: {},
            certificate1: '',
            certificate2: '',
            certificate3: '',
            info: {
                auth_id: '',
                user_id: '',
                residence: '',
                address: '',
                idcard1: '',
                idcard2: '',
                certificate_array: [],
                work_record: '',
                work_cate_id: '',
                work_cate_name: '请选择',
            }
        },
        methods: {
            init() {
                this.userInfo = get_local('userInfo');
                this.info.user_id = this.userInfo.user_id;

                this.getAuthDetail();
            },
            getAuthDetail() {
                var that = this;
                _ajax(Config.api.UserAuthAuthDetail, {
                    user_id: this.userInfo.user_id
                }, function(ret) {
                    if (ret.code === 200) {
                        console.log(JSON.stringify(ret));
                        that.info = ret.data;
                        ret.data.certificate_array.forEach(function(o, i) {
                          that['certificate'+(i+1)] = o;
                        });
                    }
                });
            },
            submit() {
                this.info.certificate_array = [];
                if (!is_define(this.info.residence)) {
                    $toast('请填写户籍');
                    return;
                } else if (!is_define(this.info.address)) {
                    $toast('请填写详细住址');
                    return;
                } else if (!is_define(this.info.work_cate_id)) {
                    $toast('请选择工种');
                    return;
                }

                if (is_define(this.certificate1)) {
                    this.info.certificate_array.push(this.certificate1);
                }
                if (is_define(this.certificate2)) {
                    this.info.certificate_array.push(this.certificate2);
                }
                if (is_define(this.certificate3)) {
                    this.info.certificate_array.push(this.certificate3);
                }

                _ajax(Config.api.UserAuthUpdate, this.info, function(ret) {
                    if (ret.code === 200) {
                        $toast("提交成功");
                        setTimeout(function() {
                            close_w();
                        }, 1000);
                    }else{
                      $toast(ret.msgs);
                    }
                });
            },
            openWork() {
                var url = '../../city/cate_win.html';
                api.openFrame({
                    name: 'mask',
                    url: url,
                    rect: {
                        x: 0,
                        y: api.winHeight - api.frameHeight,
                        w: 'auto',
                        h: 'auto'
                    },
                    bgColor: 'rgba(0,0,0,0.5)',
                    pageParam: {
                        name: api.winName,
                        frameName: api.frameName,
                    }
                });
            },
            addImg(key, flag) {
                var that = this;
                imageUpload(Config.api.ImageUploadPrivacy, function(ret) {
                    if (flag) {
                        that[key] = ret.data.imgurl;
                    } else {
                        that.info[key] = ret.data.imgurl;
                    }
                });
            }
        }

    });

    function setWork(oParent, oChild) {
        vm.info.work_cate_name = oParent.work_cate_name + '/' + oChild.work_cate_name;
        vm.info.work_cate_id = oChild.work_cate_id;
    }
</script>

</html>
